package com.item.controller;

import com.item.pojo.Shop;
import com.item.pojo.State;
import com.item.pojo.User;
import com.item.service.ShopService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class ShopController {


    @Resource
    private ShopService shopService;


    @PostMapping("/store")
    public List<Shop> findAll() {
        return shopService.list();
    }

    @PostMapping("/findStoreState")
    public List<State> findStoreState() {
        List<State> stateList = new ArrayList<>();
        stateList.add(new State(1, "开业中"));
        stateList.add(new State(2, "停业"));
        return stateList;
    }


    @PostMapping("/addStore")
    public boolean addStore(Shop shop) {
        shop.setStore_status(1);
        return shopService.saveOrUpdate(shop);
    }

    @RequestMapping("/storeFindPage")
    public Map<String, Object> findPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                        @RequestParam(value = "limit", required = false, defaultValue = "3") Integer limit,
                                        @RequestParam(value = "storeName", required = false) String storeName,
                                        @RequestParam(value = "storeState", required = false) Integer storeState) {
        return shopService.findPage(page, limit, storeName, storeState);
    }

    @PostMapping("/updateStoreState")
    public boolean updateStoreState(Integer state, Integer sid) {
        return shopService.saveOrUpdate(new Shop(sid, state));
    }

    @PostMapping("/updateStoreInfo")
    public boolean updateStoreInfo(Shop shop) {
        return shopService.saveOrUpdate(shop);
    }

    @PostMapping("/deleteStore")
    public boolean deleteStore(Integer sid) {
        return shopService.removeById(sid);
    }

}
